import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
import Layout from '@/layout/index.vue'

const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'dashboard',
        component: () => import('@v/dashboard/index.vue'),
        meta: {
          icon: 'material-symbols-light:dashboard',
          title: '首页',
          affix: true,
          noCache: true
        }
      }
    ]
  },
  {
    path: '/login',
    meta: {
      hidden: true
    },
    component: () => import('@v/login/index.vue')
  },
  {
    path: '/direct',
    component: Layout,
    meta: {
      hidden: true
    },
    // 当跳转到  /redirect/a/b/c/d?query=1做重定向
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@v/redirect/index.vue')
      }
    ]
  }
]

const asyncRoutes: RouteRecordRaw[] = [
  {
    path: '/documentation',
    component: Layout,
    redirect: '/documentation/index',
    children: [
      {
        path: 'index',
        name: 'documentation',
        component: () => import('@v/documentation/index.vue'),
        meta: {
          icon: 'carbon:document',
          title: '文档'
        }
      }
    ]
  },
  {
    path: '/guide',
    component: Layout,
    redirect: '/guide/index',
    children: [
      {
        path: 'guide',
        name: 'guide',
        component: () => import('@v/guide/index.vue'),
        meta: {
          icon: 'fluent:style-guide-24-regular',
          title: '指南'
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/menu',
    meta: {
      icon: 'grommet-icons:system ',
      title: '系统'
    },
    children: [
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@v/system/menu.vue'),
        meta: {
          icon: 'material-symbols:menu-book',
          title: '菜单'
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@v/system/role.vue'),
        meta: {
          icon: 'carbon:user-role',
          title: '角色'
        }
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@v/system/user.vue'),
        meta: {
          icon: 'solar:user-id-broken',
          title: '用户'
        }
      }
    ]
  },
  // {
  //   path: '/test-hidden',
  //   component: Layout,
  //   redirect: '/test-hidden/index',
  //   meta: {
  //     hidden: true // 父级隐藏
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'testHidden',
  //       component: () => import('@v/documentation/index.vue')
  //     }
  //   ]
  // },
  // {
  //   path: '/hide-child',
  //   component: Layout,
  //   redirect: '/hide-child/child1',
  //   meta: {
  //     icon: 'grommet-icons:system ',
  //     title: '子级都隐藏'
  //   },
  //   children: [
  //     {
  //       path: 'child1',
  //       name: 'child1',
  //       component: () => import('@v/system/menu.vue'),
  //       meta: {
  //         hidden: true
  //       }
  //     },
  //     {
  //       path: 'child3',
  //       name: 'child2',
  //       component: () => import('@v/system/role.vue'),
  //       meta: {
  //         hidden: true
  //       }
  //     }
  //   ]
  // },
  {
    path: '/external-link',
    component: Layout,
    children: [
      {
        path: 'http://www.baidu.com',
        redirect: '/',
        meta: {
          icon: 'ant-design:link-outlined',
          title: 'link Baidu'
        }
      }
    ]
  }
]

export const routes = [...constantRoutes, ...asyncRoutes]

export default createRouter({
  routes,
  history: createWebHistory()
})

/*
uniapp开发的小程序，方便师傅操作工单，管理库存，对账提现
比户家小程序展示客户订单信息，营销推广，预存充值
根据师傅状态动态加载导航tab，设置操作权限
monorepo管理组件库，抽离系统公共组件和工具函数，方便多系统复用
基于aggrid封装的复杂表格组件，覆盖多业务场景
基于elementui封装的业务组件(select、datepicker、tabs)
公司核心净水服务全流程平台，包含工单的整个生命流程，相关费用的对账结算，物料库存以及相关报表功能
统一系统布局，规范化页面样式
精简的菜单权限控制，多入口权限映射处理
支持大文件上传的实时聊天，方便沟通商家
架构升级vue2+webpack转为vue3+vite
*/
